import csv

# 定义输入文件和输出文件名
input_file = 'data1.csv'
output_file = 'output_medium.csv'

# 定义要读取并去重的列名称
col_name = 'medium'

# 用set存储去重后的medium列值
unique_vals = set()

# 读取csv文件，并将medium列的所有值添加到set中
with open(input_file, 'r',encoding='utf-8') as f_in:
    reader = csv.DictReader(f_in)
    for row in reader:
        unique_vals.add(row[col_name])

# 将去重后的值写入输出文件中
with open(output_file, 'w', newline='',encoding='utf-8') as f_out:
    writer = csv.writer(f_out)
    # 写出列标题
    writer.writerow([col_name])
    # 写出每个去重的值
    for val in unique_vals:
        writer.writerow([val])